<template>
  <Header :title="title"></Header>
  <div
    class="fui-page order-create-page fui-page-current"
    style="height: 100%; margin-top: 40px"
  >
    <div class="fui-content navbar">
      <!-- 地址 -->
      <div class="fui-list-group">
        <div class="fui-list" v-for="item in address" :key="item.id">
          <div
            class="fui-list-inner"
            style="display: flex; align-items: center"
          >
            <input
              type="radio"
              style="margin-right: 10px"
              v-model="check"
              :value="item.id"
              @change="change(item.id)"
            />
            <div class="title">
              收货人：
              <span class="realname">{{ item.name }}</span>
              <span class="mobile">{{ item.phone }}</span>
            </div>
            <div class="title">
              <span class="address">{{ item.address }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
  <script>
import { reactive, toRefs } from "vue";
import Header from "../../components/Header.vue";
import { useRoute, useRouter } from "vue-router";
import { shopOne, addOrder, changeAddr } from "../../network/index.js";

export default {
  components: {
    Header,
  },
  setup() {
    const route = useRoute();
    const router = useRouter();
    const data = new reactive({
      good: {},
      address: [],
      check: undefined,
    });

    const confirm = () => {
      addOrder({
        address: data.address[0].id,
        id: route.query.id,
      }).then((e) => {
        router.push({
          path: "/cart_pay",
          query: { id: e.order_id },
        });
      });
    };

    const change = (id) => {
      changeAddr({ id }).then(() => {
        alert("更换成功");
      });
    };

    shopOne({ id: route.query.id, token: localStorage.getItem("token") }).then(
      (e) => {
        data.good = e.good;
        data.address = e.address;
        data.check = data.address.find((item) => item.is === 1).id;
        console.log(data.check);
      }
    );

    return {
      title: "收货地址",
      confirm,
      ...toRefs(data),
      change,
    };
  },
};
</script>
  <style scoped>
.fui-page {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: #f3f3f3;
  box-sizing: border-box;
  display: none;
}
.order-create-page {
  margin: 0;
  bottom: 2rem;
  padding-bottom: 2rem;
  display: block;
  overflow: hidden;
}
.fui-content {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.fui-content.navbar {
  bottom: 2.5rem;
  padding-bottom: 2.2rem;
}
/* 地址 */
.fui-list-group {
  background-color: #fff;
  position: relative;
  margin: 0 0 0.5rem;
}
.fui-list {
  position: relative;
  display: flex;
  padding: 0.4rem 0.6rem;
  transition-duration: 300ms;
  align-items: center;
  overflow: hidden;
  padding-top: 0.8rem;
  padding-bottom: 0.83rem;
}
.fui-list-inner {
  position: relative;
  width: 100%;
  overflow: hidden;
  box-sizing: border-box;
  -ms-flex: 1;
  flex: 1;
  display: block;
  align-self: flex-start;
}
.fui-list-inner .text {
  position: relative;
  font-size: 0.7rem;
  color: #000;
  text-align: center;
}
.fui-list-inner .title {
  position: relative;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  display: flex;
  color: #000;
  font-size: 0.7rem;
  line-height: 1.2rem;
  height: 1.2rem;
}
.realname {
  display: inline-block;
  max-width: 9rem;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  padding-right: 1.2rem;
}
.mobile {
  display: inline-block;
  overflow: hidden;
}
.address {
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.65rem;
  color: #666;
}
.address_img {
  float: right;
  display: block;
}
/* 地址end */
/* 商品 */
.fui-shop {
  background-color: #fff;
  position: relative;
  margin-top: 0.5rem;
}
.fui-shop-list {
  align-items: center;
  overflow: hidden;
  transition-duration: 300ms;
  display: flex;
  padding: 0.4rem 0.6rem;
  position: relative;
  -webkit-box-align: start;
}
.fui-shop-list-media {
  display: flex;
  align-items: center;
  margin-right: 0.6rem;
  color: #aaa;
  position: relative;
  flex-wrap: nowrap;
  box-sizing: border-box;
  -webkit-box-align: center;
  flex-shrink: 0;
  -webkit-box-lines: single;
}
.img {
  width: 4rem;
  height: 4rem;
}
.shops {
  height: 3.5rem;
  align-self: center;
  justify-content: space-between;
  flex-direction: column;
  -webkit-box-pack: justify;
  display: flex;
}
.subtitle {
  color: #000;
  font-size: 0.7rem;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  white-space: normal;
}
.fui-list-angle {
  text-align: right;
  font-size: 0.7rem;
  color: #666;
  margin-right: 0.1rem;
  right: 20px;
  position: absolute;
  vertical-align: middle;
  height: 3.5rem;
  align-self: center;
  width: 3.5rem;
}
/* 买家留言 */
.fui-cell-group {
  margin-top: 0.5rem;
  background-color: #fff;
  line-height: 1.4;
  font-size: 0.8rem;
  overflow: hidden;
  position: relative;
  display: block;
}
.fui-cell-group .fui-cell {
  position: relative;
  padding: 0.75rem 0.6rem 0.65rem;
  display: flex;
  transition-duration: 300ms;
  line-height: 1.2;
  height: 2.5rem;
  align-items: flex-start;
}
.fui-cell-group .fui-cell .fui-cell-label {
  position: relative;
  display: block;
  width: 3.85rem;
  font-size: 0.7rem;
  color: #666;
  margin: 0.15rem 0 0 0;
}
.fui-cell-group .fui-cell .fui-cell-info {
  -webkit-box-flex: 1;
  flex: 1;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  font-size: 0.7rem;
  color: #000;
}
.textarea {
  width: 100%;
  background: transparent;
  border: none;
  resize: none;
  font-size: 0.7rem;
  font-family: "Helvetica Neue", Helvetica, sans-serif;
}
/* 支付按钮 */
.fui-navbar {
  position: fixed;
  width: 100%;
  bottom: 0;
  height: 2.45rem;
  background: #fff;
  z-index: 2;
}
.fui-navbar .nav-item {
  position: relative;
  display: table-cell;
  height: 2.45rem;
  text-align: center;
  vertical-align: middle;
  width: 1%;
  color: #999;
}
.total {
  padding-left: 0;
  padding-right: 0.5rem;
  font-size: 0.7rem;
  height: 2.45rem;
}
.order-create-page .buybtn {
  border: none;
  font-size: 0.7rem;
  color: #fff;
  border-radius: 0;
  width: 0.2%;
}
.fui-navbar .nav-item.btn {
  color: #fff;
  border-radius: 0;
}
.btn.btn-danger {
  background: #ff5555;
  color: #fff;
  border: 1px solid #ff5555;
}
</style>